//-------------------------------------------------------------------------
/**
   File:   mru_list.h

   Descr.: A class for Most Recent Used items. 

   Author: Stefan Leihkauf
   Date:   30.05.2012
*/
//-------------------------------------------------------------------------
#ifndef _MRU_LIST_H
#define _MRU_LIST_H

#include <vector>

template<typename ItemType>
class mru_list
{
	enum { MRULIST_MAX_ITEMS = 5 };

	typedef std::vector<ItemType> list_type;	// internal container type
	list_type _mru_list; // internal MRU list container

	unsigned _mru_list_max_items;

public:
	typedef typename list_type::iterator iterator;
	typedef typename list_type::const_iterator const_iterator;

private:
	iterator find(const ItemType& what);

public:
	/// construction
	mru_list();
	mru_list(unsigned capacity);

	/// capacity of list
	unsigned capacity() const;
	void set_capacity(unsigned capacity);

	/// number of items in list
	unsigned size() const;

	/// iterator to first item
	iterator begin();
	const_iterator begin() const;

	/// iterator behind last item
	iterator end();
	const_iterator end() const;

	/// add item (at front)
	void add(const ItemType& val);

	/// erase item
	void erase(iterator where);
	void erase(const ItemType& what);

	/// clear list
	void clear();

	/// index operator
	const ItemType& operator [] (unsigned i) const;
};

#include "mru_list.hpp"
#endif //!defined _MRU_LIST_H